﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using JKF.DataModule.SqlServerDAL;
using JKF.Substructure;
using JKF.Entities.Model;

namespace JKF.BusinessLayer.BLL
{
    /// <summary>
    /// 操作店面shop表中数据
    /// </summary>
    public partial  class bllSHOP
    {
         
        /// <summary>
        ///  获取Shop表中的数据
        /// </summary>
        /// <param name="SHOP_NAME">根据店面名称查询</param>
        /// <param name="LINKMAN">根据联系人查询</param>
        /// <param name="AREA_CODE">根据店面所在地区</param>
        /// <param name="pageCurrent">哪页</param>
        /// <param name="pageSize">页码大小</param>
        /// <param name="pageCount">总页数</param>
        /// <param name="rowCount">记录总条数</param>
        /// <returns>返回DataTable</returns>
        public DataTable GetShopsBLL(SYS_USERinfo userInfo, string SHOP_NAME, string LINKMAN, string AREA_CODE,
            int pageCurrent, int pageSize, ref int pageCount, ref int rowCount)
        {
           return dalSHOP.GetShopsDAL(userInfo,SHOP_NAME,LINKMAN,AREA_CODE,pageCurrent,pageSize,ref pageCount,ref rowCount);
        }

         /// <summary>
        /// 从数据库中获取店面编码，保证不重复
        /// </summary>
        /// <returns></returns>
        public  string GetShopCodeBLL()
        {
            return dalSHOP.GetShopCodeDAL();
        }

         /// <summary>
        /// 判断是否存在此名称店面,true表示存在
        /// </summary>
        /// <param name="shop_name">店面名称</param>
        /// <returns></returns>
        public bool ExistsShopNameBLL(string shop_name)
        {
            return dalSHOP.ExistsShopNameDAL(shop_name);
        }
        /// <summary>
        /// 取店铺列表
        /// </summary>
        /// <returns></returns>
        public string GetShopArea()
        {
            //const string cacheName = "Shop_CodeOne";
            //if (!CacheManage.HadCache(cacheName))
            //{ 
                // 判断当前用户的角色去加载对应的角色下拉列表 
                List<SHOPinfo> oList;
                string condition = string.Format(@" shop_code in(  select b.shop_code 
from   dbo.SYS_USER a
inner join sys_user_shop b on a.user_key=b.user_key
where b.user_key='{0}')", bllSYS_USER.CurrentUser.USER_KEY.ToString());
                oList = this.GetModelList(condition); 
                var sb = new StringBuilder();
                if (oList.Count == 0)
                {
                    sb.AppendFormat("<option value=\"{0}\">{1}</option>", "-1", "获取店面失败，请与管理员联系！"); 
                    //CacheManage.AddCache(cacheName, sb.ToString());
                    //return CacheManage.GetCache(cacheName).ToString();
                    return sb.ToString();
                }
                foreach (var item in oList)
                {
                    sb.AppendFormat("<option value=\"{0}\">{1}</option>", item.SHOP_CODE, item.SHOP_NAME);
                } 
                //CacheManage.AddCache(cacheName, sb.ToString());
            //}
                return sb.ToString();
            //return CacheManage.GetCache(cacheName).ToString();
        }

        /// <summary>
        /// 向店面插入数据
        /// </summary>
        /// <param name="shop_code">店面编码</param>
        /// <param name="area_code">地区编码</param>
        /// <param name="sql">sql语句</param>
        /// <param name="now_user_key">当前操作员ID</param>
        /// <returns>返回执行结果，返回1表示成功</returns>
        public string TransactionSQLAddBLL(string shop_code, string area_code, string sql, string now_user_key)
        {
            return dalSHOP.TransactionSQLAddDAL(shop_code, area_code, sql, now_user_key);
        }
        /// <summary>
        /// 更新店面数据
        /// </summary>
        /// <param name="shop_code">店面编码</param>
        /// <param name="area_code">地区编码</param>
        /// <param name="sql">sql语句</param>
        /// <param name="now_user_key">当前操作员ID</param>
        /// <returns>返回执行结果，返回1表示成功</returns>
        public  string TransactionSQLUpdateBLL(string shop_code, string area_code, string sql, string now_user_key)
        {
            return dalSHOP.TransactionSQLUpdateDAL(shop_code, area_code, sql, now_user_key);
        }
         /// <summary>
        /// 事务删除店面
        /// </summary>
        /// <param name="shop_code">店面编码</param>
        /// <returns></returns>
        public  string TransactionSQLDeleteBLL(string shop_code)
        {
            return dalSHOP.TransactionSQLDeleteDAL(shop_code);
        }
    }
}
